const app = getApp()
const md5 = require('../../../../utils/md5.js');
const http = require('../../../../utils/http.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        longitude: '',
        latitude: '',
        orderId:'',
        markers: [],
        mapControls: [{   //地图中心
            id: 0,
            position: {                 //相对定位
                left: app.globalData.scWidth * 0.47,
                top: app.globalData.scHeight * 0.29,
                width: app.globalData.scHeight * 0.032,
                height: app.globalData.scHeight * 0.05

            },
            iconPath: "/images/d0.png",
            width: 30,
            height: 20,
            clickable: false
        }, {
            id: 1,
            position: {                 //相对定位
                left: app.globalData.scWidth * 0.00,
                top: app.globalData.scHeight * 0.38,
                width: app.globalData.scWidth * 0.15,
                height: app.globalData.scHeight * 0.091
            },
            iconPath: "/images/dw.png",          //相对于当前文件的路径
            clickable: true
        }
        ],
        flag: [0],
        startext: [''],
        stardata: [1, 2, 3, 4, 5],
        apprise:''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.mapCtx = wx.createMapContext("myMap")
        this.mapCtx.moveToLocation()
        var orderId = options.orderId
        this.setData({
          orderId: orderId
        })
    },
    regionchange(e) {
        /** 中心点的位置 **/
        if (e.type == "end") {
            var that = this;
            console.log(that);
            this.mapCtx.getCenterLocation({
                success: (res) => {
                    console.log(res.latitude);
                    console.log(res.longitude);
                }
            })
        }
    },
    mapControlTap(e) {

        switch (e.controlId) {
            case 1:
                this.mapCtx.moveToLocation()
                break;
        }
    },
    clickraise() {
      var token = wx.getStorageSync('token')
      var orderId = this.data.orderId
      // 获取评语
      var evaluate = this.data.startext[0]
      // 获取星级
      var star = this.data.flag[0]
      var data = {
        method: 'Order.evaluate',
        token: token,
        orderId: orderId,
        evaluate: evaluate,
        star:star
      }
      var arr = http.sorts(data)
      data.sign = md5.hex_md5(arr)
      console.log(arr)
      http._post(data, res => { 
        console.log(res)
        wx.reLaunch({
          url: '/pages/index/lymap/lymap',
        })
      })
        
    },
    changeColor: function (e) {
        let index = e.currentTarget.dataset.index;
        console.log(index)
        let num = e.currentTarget.dataset.no;
        console.log(num)
        let a = 'flag[' + index + ']';
        console.log(a)
        let b = 'startext[' + index + ']';
        console.log(b)
        let that = this;
        if (num == 1) {
            that.setData({
                [a]: 1,
                [b]: '非常不满意',
                apprise:'感谢你的评价，我们会继续努力'
            });
        } else if (num == 2) {
            that.setData({
                [a]: 2,
                [b]: '不满意',
                apprise: '感谢你的评价，我们会继续努力'
            });
        } else if (num == 3) {
            that.setData({
                [a]: 3, 
                [b]: '一般',
                apprise: '感谢你的评价，我们会继续努力'
            });
        } else if (num == 4) {
            that.setData({
                [a]: 4,
                [b]: '满意',
                apprise: '感谢你的评价，我们会继续努力'
            });
        } else if (num == 5) {
            that.setData({
                [a]: 5,
                [b]: '非常满意',
                apprise: '感谢你的评价，我们会继续努力'
            });
        }
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        let _this = this;
        wx.getLocation({
            type: 'gcj02',
            success: (res) => {
                _this.setData({
                    latitude: res.latitude,
                    longitude: res.longitude,
                    markers: [{
                        id: "0",
                        latitude: res.latitude,
                        longitude: res.longitude,
                        iconPath: '/images/d2.png',
                        width: 30,
                        height: 32
                    }, {
                        id: "1",
                        latitude: res.latitude - 0.001,
                        longitude: res.longitude,
                        iconPath: '/images/d1.png',
                        width: 30,
                        height: 32,
                        callout: {
                            content: "地址",
                            bgColor: "#ffffff",
                            color: "#ff0000",
                            padding: 10,
                            borderRadius: 5,
                            display: 'BYCLICK'
                        }
                    }, {
                        id: "2",
                        latitude: res.latitude + 0.0007,
                        longitude: res.longitude,
                        iconPath: '/images/d1.png',
                        width: 30,
                        height: 32,
                        callout: {
                            content: "地址",
                            bgColor: "#ffffff",
                            color: "#ff0000",
                            padding: 10,
                            borderRadius: 5,
                            display: 'BYCLICK'
                        }
                    }, {
                        id: "3",
                        latitude: res.latitude,
                        longitude: res.longitude - 0.001,
                        iconPath: '/images/d1.png',
                        width: 30,
                        height: 32,
                        callout: {
                            content: "华星时代广场",
                            bgColor: "#ffffff",
                            color: "#999",
                            padding: 10,
                            display: "ALWAYS",
                            borderRadius: 20,

                        }
                    }

                    ]
                })

            }
        })
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})